package com.me.common.base;

import lombok.Data;

/**
 * 通用返回类
 *
 * @author zhenglei
 * @since 2022/4/15 16:59
 */
@Data
public class CommonResult<T> {
    /**
     * 状态码
     */
    private Integer code = 20000;
    /**
     * 信息
     */
    private String message;
    /**
     * 数据
     */
    private T data;


    public static <T> CommonResult<T> success() {
        return new CommonResult<>();
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(data);
    }

    public static <T> CommonResult<T> success(T data, String message) {
        return new CommonResult<>(data, message);
    }

    public static <T> CommonResult<T> error() {
        return new CommonResult<>(50000, null);
    }

    public static <T> CommonResult<T> error(String message) {
        return new CommonResult<>(50000, message);
    }

    public CommonResult(T data) {
        super();
        this.data = data;
    }

    public CommonResult(T data, String message) {
        super();
        this.data = data;
        this.message = message;
    }

    public CommonResult(Integer code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    public CommonResult() {

    }
}
